package core.resources
{
import core.Configuration;

import flash.events.Event;
import flash.net.URLLoader;

import framework.dao.EntryUtil;

import values.map.MapValue;

/**
 * MapDataResourceTask
 * @author jliang
 *
 */
public class MapDataResourceTask extends LoadTaskBase
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function MapDataResourceTask()
	{
		super();
	}
	
	override public function start():void
	{
		if (params.data)
		{
			complete();
			return;
		}
		
		var url:String = Configuration.configPath + params.url;
		startToLoad(url, dataLoadedHandler);
	}
	
	private function dataLoadedHandler(event:Event):void
	{
		var loader:URLLoader = event.target as URLLoader;
		loader.removeEventListener(Event.COMPLETE, dataLoadedHandler);
		
		params.data = EntryUtil.mapping(XML(loader.data), MapValue);
		
		complete();
	}
}
}